package vista;

import java.awt.Color;
import java.awt.Font;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
import java.net.URL;


import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JButton;

import modelo.Configuracion;

public class VistaUtils {
	/*METODOS ESTATICOS*/
	
	public static void decorarBoton(JButton btn) {
		//Icono
		ImageIcon icono = cargarIcono(Configuracion.PATH_IMAGENES + "botonrojo.png");
		btn.setIcon(icono);	
		btn.setVerticalTextPosition(AbstractButton.CENTER);
		btn.setHorizontalTextPosition(AbstractButton.CENTER);
		btn.setBorderPainted(false);			
		btn.setFont(cargarFuente(Configuracion.PATH_FUENTES + "aura.ttf"));
		btn.setForeground(Color.WHITE);

		
		btn.addMouseListener(new VistaMouseListener(btn));
	}
	
	public static ImageIcon cargarIcono(String path) {
		URL imgURL = VistaUtils.class.getResource(path);
		if (imgURL != null) {
			return new ImageIcon(imgURL);
		} 
		else {
			System.err.println("No se puede cargar el icono: " + path);
			return null;
		}
}

	public static Font cargarFuente(String path) {
		try{
			File file = new File(path);
			FileInputStream fis = new FileInputStream(file);
			Font font = Font.createFont(Font.TRUETYPE_FONT, fis);
			return font.deriveFont(0,15);
		}
		catch(Exception e) {
			return null;
		}
	}	
}

class VistaMouseListener implements java.awt.event.MouseListener {
	   
	   private javax.swing.JButton boton;
	   
	   public VistaMouseListener(javax.swing.JButton boton){
	      this.boton = boton;
	   }
	
	   public void mouseEntered(java.awt.event.MouseEvent e) {
		   ImageIcon icono = VistaUtils.cargarIcono(Configuracion.PATH_IMAGENES + "botonOver.png");
		   boton.setIcon(icono);	
		   boton.setForeground(Color.BLACK);
	   }
	
	   public void mouseExited(java.awt.event.MouseEvent e) {
		   ImageIcon icono = VistaUtils.cargarIcono(Configuracion.PATH_IMAGENES + "botonUp.png");
		   boton.setIcon(icono);
		   boton.setForeground(Color.WHITE);
	   }

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
	
		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
	
		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

	} 
